package org.hot100_5.leetcode141;

import org.leetcode.easy.ListNode;

import java.util.List;

public class Solution {
    public boolean hasCycle(ListNode head) {

        if (head==null || head.next==null ){
            return false;
        }

        ListNode slow = head;
        ListNode fast = head.next;

        while (fast!=null){
            if (fast==slow){
                return true;
            }

            slow = slow.next;
            fast = fast.next;
            if (fast!=null){
                fast = fast.next;
            }
        }


        return false;
    }
}
